import Base from "./Base";
import { idToRgba } from "src/utils/helper";
import utils from 'src/utils'
interface RectProps {
    x: number;
    y: number;
    size: number;
    lineHeight: number
}

export default class extends Base {
    private count: number = 0
    public textRow: number = 0
    constructor(option: RectProps) {
        super()
        utils.object.Assign(option, this.props)
    }
    draw(ctx: CanvasRenderingContext2D, osCtx: OffscreenCanvasRenderingContext2D): void {
        const { x, y, size, width } = this.props
        if (!ctx || !osCtx) return
        let h = 0
        ctx.font = `${size}px Arial`
        h = ctx.measureText('你好').actualBoundingBoxDescent
        ctx.save()
        ctx.beginPath()
        ctx.rect(x + (width + this.count), (y + (size * (this.textRow - 1))) + h, 0, size)
        ctx.closePath()
        ctx.stroke()
        ctx.restore()
        // 镜像画布
        const [r, g, b, a] = idToRgba(this.getRgbaId());

      
        osCtx.strokeStyle = `rgba(${r}, ${g}, ${b}, ${a})`
        osCtx.save()
        osCtx.beginPath()
        osCtx.rect(x + (width + this.count), (y + (size * (this.textRow - 1))) + h, 0, size)
        osCtx.closePath()
        osCtx.stroke()
        osCtx.restore()
    }

    // getTextWidth(text: string, size: number) {
    //     this.ctx.font = `${size}px Arial`
    //     return this.ctx.measureText(text).width
    // }

}